﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PPI.Entities.Interface;
using System.Data;
using PPIDataAccess.Distribution;
using PPI.Mobile;
using System.Data.SqlClient;
using PPI.Data;

namespace PPI.ServiceLogic.Distribution
{
    public enum DistributionLookupType
    {
        Kv = 1,
        TransformerType,
        Type, 
        Class,
        Phase,
        PCBType,
        ConductorType,
        ACSR,
        ArrestorKv,
        CutoutKv,
        Keywords
    }

    public class LDistributionLookup : IMobileTable
    {
        public static DataSet SelectAllIdName(string connectionKey)
        {
            return DDistributionLookup.SelectAll(connectionKey);
        }

        #region IMobileTable Members

        public List<PPI.Mobile.EMobileQuery> CreateInsertMobileQuery(string connectionKey)
        {
            DataTable lookups = DDistributionLookup.SelectAll(connectionKey).Tables[0];

            List<EMobileQuery> listQueries = new List<EMobileQuery>();
            listQueries.Add(new EMobileQuery(string.Format("DELETE tb_Transformers_Lookups")));

            EMobileQuery insertQuery = new EMobileQuery("INSERT INTO tb_Transformers_Lookups (idLookup, Text, Type) VALUES (@idLookup, @text, @type)");

            foreach (DataRow lookup in lookups.Rows)
            {
                List<SqlParameter> parameters = new List<SqlParameter>();

                parameters.Add(DBHelper.CreateIntParameter("@idLookup", ParameterDirection.Input, false, Convert.ToInt32(lookup["Vendor_Distribution_LookupId"])));
                parameters.Add(DBHelper.CreateIntParameter("@type", ParameterDirection.Input, false, Convert.ToInt32(lookup["LookUpType"])));
                parameters.Add(DBHelper.CreateNVarCharParameter("@text", 100, ParameterDirection.Input, false, lookup["LookUpText"]));

                insertQuery.Parameters.Add(parameters);
            }

            listQueries.Add(insertQuery);

            return listQueries;
        }

        #endregion
    }
}
